import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/healthcode',
    name: 'HealthCode',
    component: () => import('../views/HealthCode.vue'),
  },
  {
    path: '/travelpolicy',
    name: 'TravelPolicy',
    component: () => import('../views/eight_part/TravelPolicy.vue')
  },
  {
    path: '/article',
    name: 'Article',
    component: () => import('../views/Article.vue'),
    meta: {
      keepAlive: false  //Article 不希望被缓存
    }
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('../views/Register.vue'),
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login.vue'),
  },
  {
    path: '/addpatient',
    name: 'Addpatient',
    component: () => import('../views/AddPatient.vue'),
  },
  {
    path: '/patientmanagement',
    name: 'routeName',
    component: () => import('../views/PatientManagement.vue'),
  },
  {
    path: '/personalcenter',
    name: 'PersonalCenter',
    component: () => import('../views/PersonalCenter.vue'),
  },
  {
    path: '/onlineservice',
    name: 'OnlineService',
    component: () => import('../views/OnlineService.vue'),
  },
  {
    path: '/epidemicdata',
    name: 'EpidemicData',
    component: () => import('../views/EpidemicData.vue'),
  },

  {
    path: '/home',

    name: 'Home',
    component: Home
  },
  {
    path: '/hospitallist',
    name: 'HospitalList',
    component: () => import('../views/HospitalList.vue'),
  },
  {
    path: '/hospitaldetails',
    name: 'HospitalDetails',
    component: () => import('../views/HospitalDetails.vue'),
  },

  {
    path: '/order',
    name: 'Order',
    component: () => import('../views/Order.vue')
  },
  {
    path: '/ordersuccess',
    name: 'OrderSuccess',
    component: () => import('../views/OrderSuccess.vue'),
  },
  {
    path: '/choosepatient',
    name: 'ChoosePatient',
    component: () => import('../views/ChoosePatient.vue'),
  },
  {
    path: '/testresults',
    name: 'TestResults',
    component: () => import('../views/TestResults.vue'),
  },
  {

    path: '/doctor',
    name: 'Doctor',
    component: () => import('../views/Doctor.vue'),
  },
  {
    path: '/trackvaccine',
    name: 'TrackVaccine',
    component: () => import('../views/eight_part/TrackVaccine.vue'),
  },
  {
    path: '/typeofvirus',
    name: 'TypeOfVirus',
    component: () => import('../views/eight_part/TypeOfVirus.vue'),
  },
  {
    path: '/checkreport',
    name: 'CheckReport',
    component: () => import('../views/CheckReport.vue'),
  },
  {
    path: '/epidemicgoods',
    name: 'EpidemicGoods',
    component: () => import('../views/eight_part/EpidemicGoods.vue'),
  },
  {
    path: '/bodytable',
    name: 'BodyTable',
    component: () => import('../views/eight_part/BodyTable.vue'),
  },
  {
    path: '/tableresult',
    name: 'TableResult',
    component: () => import('../views/eight_part/TableResult.vue'),
  },
  {
    path: '/pofscience',
    name: 'PopularizationOfScience',
    component: () => import('../views/eight_part/PopularizationOfScience.vue'),
  },
  {
    path: '/choosetest',
    name: 'ChooseTest',
    component: () => import('../views/eight_part/ChooseTest.vue'),
  },
  {
    path: '/selfevaluation',
    name: 'SelfEvaluation',
    component: () => import('../views/eight_part/SelfEvaluation.vue'),
  },
  {
    path: '/foodresult',
    name: 'FoodResult',
    component: () => import('../views/eight_part/FoodResult.vue'),
  },

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  if (sessionStorage.getItem('uid') && sessionStorage.getItem('islogin')) {
    next()
  } else {
    if (to.path == '/login' || to.path == '/register') {
      next()
    } else {
      next('/login')
    }
  }
})
export default router
